<template>
    <div id="app">
        <router-view></router-view>
    </div>
</template>

<script>
export default {
    name: 'app',
    components: {
        cjcNav: () => import('./components/common/Nav.vue')
    },
    created() {
        this.$Message.config({
            top: 300,
            duration: 3
        })
        const Vm = this
        const State = Vm.$store.state
        let saveUserInfo = null
        /**
         * 确认用户信息,并保存用户信息
         */
        async function setUserInfo() {
            if (!State.production) {
                // 调用JS-API登录
                await Vm.$cjc.apiLogin({
                    appKey: '0000',
                    success: (data) => { // 执行成功回调
                        Vm.$cjc.cjcLog('getlogin success' + data)
                    },
                    fail: (data) => { // 执行失败回调 只要是失败 不论是执行失败还是返回值是失败都会进fail
                        Vm.$cjc.cjcLog('getlogin fail' + data)
                    }
                })
                Vm.$cjc.hiddenNavigation()
                let userInfo = await Vm.$cjc.apiGetUserInfor()
                Vm.$store.commit('SET_userInfo', userInfo.result)
                saveUserInfo = await Vm.$store.dispatch('saveUserInfo', userInfo.result)
            } else {
                // 测试账号登录
                let userLogin = await Vm.$store.dispatch('userlogin', {
                    'username': 'koumeilin',
                    'password': '123',
                    'type': 2,
                    version_code: 20,
                    version_name: '1.1.2',
                    client_type: 1
                })
                Vm.$store.commit('SET_userInfo', userLogin.data.result)
                saveUserInfo = await Vm.$store.dispatch('saveUserInfo', userLogin.data.result)
            }
        }
        function skipRoutre() {
            let IDENTITY = saveUserInfo.data.result.IDENTITY_CODE
            if (IDENTITY === 10001) {
                Vm.$router.replace({
                    name: 'stuHome'
                })
            } else if (IDENTITY === 20001) {
                Vm.$router.replace({
                    name: 'staff'
                })
            } else if (IDENTITY === 20002) {
                Vm.$router.replace({
                    name: 'SAhome'
                })
            } else if (IDENTITY === 30001) {
                Vm.$router.replace({
                    name: 'AdHome'
                })
            }
        }
        // 执行步骤
        async function Step() {
            await setUserInfo()
            skipRoutre()
        }
        Step()
    }
}
</script>
<style lang="less">
@size-color: #495060;
body {
    background-color: #f8f8f8;
}

#app {
    height: 100vh;
    background-color: #f8f8f8;
    padding-top: 50px;
}
</style>

